Skip to content

fix json deserialization into stableswap pool type #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

sampocs
Copy link
Contributor

@sampocs sampocs commented Aug 28, 2023

Context

The stableswap pool type has a scaling factor attribute of type Vec<u64>; however, the json schema defines the same field as an array of Strings. As a result, when querying this pool, the deserialization fails. This PR adds a custom serializer/deserializer to safely convert the Vec<String> type from the query response into the preferred Vec<u64> type.

Brief Changelog

  • Added as_str_vec serializers and deserializers
  • Added the functions as annotations to the scaling factor attribute

Code to reproduce the error

use osmosis_std::types::osmosis::gamm::poolmodels::stableswap::v1beta1::Pool as StableswapPool;
use osmosis_std::types::osmosis::poolmanager::v1beta1::PoolmanagerQuerier;

let query_pool_resp = PoolmanagerQuerier::new(&deps.querier).pool(pool_id)?;
let stableswap_pool: StableswapPool = query_pool_resp
    .pool
    .ok_or(ContractError::PoolNotFoundOsmosis { pool_id })?
    .try_into()
    .map_err(|e| {
        StdError::parse_err(
            "osmosis_std::types::osmosis::gamm::poolmodels::stableswap::v1beta1::Pool",
            e,
        )
    })?;

Error message before fix

Error: rpc error: code = InvalidArgument desc = failed to execute message; message index: 0: Error parsing into type osmosis_std::types::osmosis::poolmanager::v1beta1::PoolResponse: Invalid type string "100000". Expected u64: execute wasm contract failed: invalid request

@sampocs sampocs changed the title fix json deserialization in stableswap pool type fix json deserialization into stableswap pool type Aug 28, 2023
@iboss-ptk
Copy link
Collaborator

Hi @sampocs! would you mind making this automated? With the current change, it will be replaced when type gets regenerated.

This is similar to

pub fn allow_serde_int_as_str(s: ItemStruct) -> ItemStruct {

So we can add another transformer function next to allow_serde_int_as_str and register it here:

transformers::allow_serde_int_as_str(s)

@sampocs
Copy link
Contributor Author

sampocs commented Sep 13, 2023

Sorry for the delay @iboss-ptk! Please see the above commit and let me know if this addresses it for you.

Also, how can I test this?

@iboss-ptk
Copy link
Collaborator

@sampocs sorry for late response, you can unit test the transformer logic similar to these tests (basically test if the transformed tokens match expectation).

To see if actual code generation works as expected, you can cd packages/proto-build && cargo run (note that cargo run -p proto-build does not work for some reason I haven't investigated).

@iboss-ptk iboss-ptk added the bug Something isn't working label Sep 20, 2023
@iboss-ptk iboss-ptk added this to the v1.19.0 milestone Sep 20, 2023
@iboss-ptk
Copy link
Collaborator

The changes and the fix is already in main 473d539

@iboss-ptk iboss-ptk closed this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants